Imports System.Data.SqlClient
Imports System.IO
Imports System.Text
Public Class f_DCTTablePKSelection
    Dim objhdlr As New Cls_DCTDevHdlr
    Dim str As String = "data source=.;initial catalog=" & f_DCTDevPreparation.f & ";persist security info=False;user id=realm;password=friend;packet size=4096"
    Private Sub f_DCTTablePKSelection_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        loadddl()
    End Sub
    Private Sub ddlDCTtables_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ddlDCTtables.SelectedIndexChanged
        If ddlDCTtables.SelectedIndex > 0 Then
            loadgrid()
        End If
    End Sub
    Private Sub btnsetPKFields_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnsetPKFields.Click
        Dim objparent As New Cls_DCTPKSelection
        Dim objchild As New Str_DCTPKSelection
        Dim alPKName As New ArrayList
        Dim strConString As String = "data source=.;initial catalog=" & f_DCTDevPreparation.f & ";persist security info=False;user id=realm;password=friend;packet size=4096"
        Dim i As Integer
        If ddlDCTtables.SelectedIndex > 0 Then
            i = dgdPKFields.Rows.Count
            For i = 0 To i - 1
                objchild.tablename = ddlDCTtables.Text
                objchild.tblID = ddlDCTtables.SelectedValue
                objchild.ColumnName = dgdPKFields.Rows(i).Cells(1).Value
                If dgdPKFields.Rows(i).Cells(0).Value = 1 Then
                    objchild.checked = 1
                Else
                    objchild.checked = 0
                End If
                alPKName.Add(objchild)
            Next
            objparent.PKnames = alPKName
            objhdlr.InsertPKData(objparent, strConString)
            MessageBox.Show("Primary Keys Selected successfully")
            loadddl()
            loadgrid()
        Else
            MessageBox.Show("Please Select a Table Name")
        End If
    End Sub
    Private Sub loadgrid()
        Dim ds As New DataSet
        ds = objhdlr.GetDCTTableColumns(ddlDCTtables.SelectedValue, str)
        dgdPKFields.DataSource = ds.Tables(0).DefaultView
        dgdPKFields.Columns("name").DisplayIndex = 0
        dgdPKFields.Columns("PKSelect").DisplayIndex = 1
        dgdPKFields.AutoResizeColumns()
    End Sub
    Private Sub btnDonePK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDonePK.Click
        Dim f1 As New f_ScriptDirSelection
        'f1.Show()
        Me.Hide()
    End Sub
    Private Sub loadddl()
        Dim objcmd As New SqlCommand
        Dim objcon As New SqlConnection(str)
        Dim ds As New DataSet
        ds = objhdlr.GetDCTTableNames(str)
        ddlDCTtables.DataSource = ds.Tables(0)
        ddlDCTtables.DisplayMember = "Name"
        ddlDCTtables.ValueMember = "tblID"
        ddlDCTtables.SelectedIndex = 0
        objcon.Close()
        objcon.Dispose()
        objcon = Nothing
    End Sub
End Class